<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2019/9/9
 * Time: 11:32
 */
namespace app\admin\controller;
use think\Db;
class Recharge extends Base {
    public function index(){
        if(request()->isAjax()){
            extract(input());
            $map =array();
            $page = input('page') ? input('page'):1;
            $limit = input("limit")?input("limit"):10;// 获取总条数;
            if(isset($keyword)&&$keyword!="")
            {
                $map['uuu.user_username|uuu.user_phone'] = ['like',"%" . $keyword . "%"];
            }
            if(isset($withdraw_status)&&$withdraw_status!="")
            {
                $map['recharge_status'] = $withdraw_status;
            }
            if(isset($start)&&$start!=""&&isset($end)&&$end=="")
            {
                $map['a.recharge_time'] = ['>= time',$start];
            }
            if(isset($end)&&$end!=""&&isset($start)&&$start=="")
            {
                $map['a.recharge_time'] = ['<= time',$end];
            }
            if(isset($start)&&$start!=""&&isset($end)&&$end!="")
            {
                $map['a.recharge_time'] = ['between time',[$start,$end]];
            }

            $count = Db::table('up_recharge')->alias('a')
                ->join('up_u_user uuu','uuu.user_id = a.recharge_user_id','left')
                ->where($map)
                ->count();
            $list = Db::table('up_recharge')->alias('a')
                ->join('up_u_user uuu','uuu.user_id = a.recharge_user_id','left')
                ->where($map)
                ->field('uuu.user_username,uuu.user_phone,uuu.user_id,a.*')
                ->order('recharge_time desc')
                ->page($page, $limit)
                ->select();//计算总页面

            return json(['code'=>220,'msg'=>'','count'=>$count,'data'=>$list]);
        }
        return $this->fetch();
     }
}